<style type="text/css">
	.layui-upload-drag {
	    position: relative;
	    padding: 10px;
	    border: 1px dashed #e2e2e2;
	    background-color: #fff;
	    text-align: center;
	    cursor: pointer;
	    color: #999;
	}
</style>
<div class="layui-input-block">
	<div class="layui-upload-drag">
	 	<a href="<if condition='$imgUrl neq null'>{$imgUrl}<else/>javascript:void(0);</if>" <if condition="$imgUrl neq null">target="black"</if>>
	 		<img id="{$name}_show_id" src="<if condition='$imgUrl neq null'>{$imgUrl}<else/>/Public/Admin/images/default_upload.png</if>" alt="上传图片" width="{$imgW}" height="{$imgH}">
	 	</a>
	 	<input type="hidden" id="{$name}" name="{$name}" value="<if condition='$img neq null'>{$img}</if>">
	</div>
	<div style="margin-top:10px;">
		<button type="button" class="layui-btn" id="btnUploadImg_{$name}"><i class="layui-icon">&#xe67c;</i>上传{$nameStr}</button>
	</div>
	<if condition="$sizeStr neq null">
	<div class="layui-form-mid layui-word-aux">建议尺寸：{$sizeStr}</div>
	</if>
</div>
<script type="text/javascript">
layui.config({
	base: '__ADMIN__'
}).extend({
	croppers: '/lib/extend/cropper/croppers',
}).use(['upload','croppers'],function(){
	
	//声明变量
	var layer = layui.layer
	,upload = layui.upload
	,croppers = layui.croppers
	,$ = layui.$;
	
	if({$isCrop}==1) {
		
		//图片裁剪组件
	    croppers.render({
	        elem: '#btnUploadImg_{$name}'
	        ,name:"{$name}"
	        ,saveW:{$cropW}     //保存宽度
	        ,saveH:{$cropH}
	        ,mark:{$cropRate}    //选取比例
	        ,area:'900px'  //弹窗宽度
	        ,url: mUrl + "/upload/uploadImg"
	        ,done: function(url){ 
	        	//上传完毕回调
	            $('#{$name}').val(url);
	            $('#{$name}_show_id').attr('src',url);
	        }
	    });
		
	}else{
		
		/**
		 * 普通图片上传
		 */
		var uploadInst = upload.render({
		    elem: '#btnUploadImg_{$name}'
			,url: mUrl + "/upload/uploadImg"
			,accept:'images'
			,acceptMime:'image/*'
			,exts: "{$uploadImgExt}"
			,field:'file'//文件域字段名
			,size: {$uploadImgSize} //最大允许上传的文件大小
			,before: function(obj){
				//预读本地文件
			}
			,done: function(res){
				//上传完毕回调
				
				if(!res.success){
					layer.msg(res.msg,{ icon: 5 });
					return false;
				}

				//上传成功
				$('#{$name}_show_id').attr('src', res.data);
	    		$('#{$name}').val(res.data);
			}
			,error: function(){
				//请求异常回调
				return layer.msg('数据请求异常');
			}
		});
		
	}
	
});

</script>